Wrap PySerial inside busio.UART for Linux platforms - #1106
Merged
makermelissa merged 2 commits intoApr 17, 2026
Merged
Conversation
Fixes adafruit#332. Instead of raising RuntimeError on embedded Linux, busio.UART now uses a new generic_linux UART backend that wraps PySerial. This lets CircuitPython UART code run unchanged on Linux / SBC boards. Changes: - Add src/adafruit_blinka/microcontroller/generic_linux/uart.py PySerial-backed UART with full CircuitPython API (read, readinto, readline, write, deinit, baudrate, in_waiting, timeout, reset_input_buffer). - Update busio.UART to import the generic_linux backend when detector.board.any_embedded_linux is true, matching the pattern used by busio.I2C and busio.SPI. - Add missing CircuitPython API members to busio.UART: - timeout property (getter/setter) - __enter__() / __exit__() context manager - reset_input_buffer() - baudrate as a proper property (getter/setter) - Fix timeout default from 1000 (stale milliseconds) to 1 (seconds), matching CircuitPython 4.0+ convention.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #332.
Instead of raising
RuntimeErroron embedded Linux,busio.UARTnow wraps PySerial via a newgeneric_linuxUART backend. This lets CircuitPython UART code run unchanged on Linux / SBC boards (Raspberry Pi, BeagleBone, etc.).Changes
New file:
src/adafruit_blinka/microcontroller/generic_linux/uart.py/dev/device paths automatically (/dev/serial0,/dev/ttyS0,/dev/ttyAMA0, etc.)read,readinto,readline,write,deinit,reset_input_bufferbaudrate,in_waiting,timeoutUpdated:
src/busio.pyUART.__init__now importsgeneric_linux.uartwhendetector.board.any_embedded_linuxis true (instead of raisingRuntimeError)busio.I2Candbusio.SPIfor Linux supporttimeoutproperty (getter/setter)__enter__()/__exit__()context manager supportreset_input_buffer()methodbaudrateas a proper property (getter/setter) instead of a plain attributetimeoutdefault from1000(stale milliseconds value) to1(seconds), matching CircuitPython 4.0+ conventiondeinit()to call the backend'sdeinit()when availableUsage
Notes
pyserial) must be installed but is not added toinstall_requires— it's already commonly available on Linux SBC setups and is used elsewhere in the project (e.g. RP2040 U2IF)uartPortsfrom the board's pin definitions (same as I2C usesi2cPorts)